Avoid reporting on values from module types#52
Open
fantazio wants to merge 5 commits intoLexiFi:masterfrom
Open
Avoid reporting on values from module types#52fantazio wants to merge 5 commits intoLexiFi:masterfrom
fantazio wants to merge 5 commits intoLexiFi:masterfrom
Conversation
The new pattern was observed on Frama-C. It is described in `examples/using_dune/lib/values/builder_sig_api/README.md`. It uses a mix of module types, functors and includes dispatched in multiple files. It is not uncommon to use a `.ml` (without `.mli`) to expose module types and reuse these in other module's `.mli`. This pattern will need to be tested more specifically. The current report semantic for the values in module types is to not report them.
It is not uncommon to use a `.ml` (without `.mli`) to expose module types and include these in other module's `.mli`. The new tests specifically target this pattern with a toplevel `include` The current report semantic for the values in module types is to not report them.
Instead of including a modtype from an external module in the signature, the same module both defines and includes a modtype in its signature. The current report semantic for the values in module types is to not report them.
It was first retrieved by traversing the `cmi_infos.cmi_sign`, and if no candidate was found then the fallback was the sourcepath in `with_cmt` if available (see 6294e18). The retrieval in `cmi_infos.cmi_sign` now uses lowercased units and is reduced to either an exact match or a suffix match. If neither is found, then the fallback is applied. The fallback still relies on `with_cmt`'s sourcepath (if available), but first checks if there is a `.cmti` available. If it exists, then the sourcepath is updated to a `.mli` file. Otherwise the sourcepath is used as is. This difference in the fallback assumes a bijection between `.cmti` and `.mli` (which is the case according to `-bin-annot`'s documentation). The fixed FP witness the improvement of the sourcepath selection : the "re-exports" from other modules are removed.
The report semantic for values exported by module types is to not report them. In order to ensure they are not exported, this change introduces a new "stock" in `DeadCommon`: `in_modtype`. It is used in `DeadCode.collect_export`. It remembers the locations of values exposed in module types and is used to ensure such values are not added to the `decs` stock.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Include changes from #49.
Fix #50 by implementing the described "easy way".
The sourcepaths retrieval for cmi files is improved by :
cmi_infos.cmi_sign. Now the units (of the cmi and locations' fnames) are lowercased for comparison and only exact matches or suffix matches are considered. Prefix matches and simply different units are not considered as valid candidates anymore. See 6294e18 for details on the previous algorithm.This improvement fixed the duplicated reports issue (due to "re-exports") described in #50.
During the analysis, exported values in module types are tracked separately to ensure they are not tracked with reportable values.
Testing on Frama-C, this change does not impact performances of the dead_code_analyzer. The changes in the updated results only contain removals of reported values declared in module types.
Note
I also tested a reversed version of the sourcepath retrieval for cmi files : first look for a cmti file, then fallback on the cmt's sourcepath, then traverse the
cmi_infos.cmi_sign. It was significantly slower on Frama-C (15-20%) and did not provide as good results as the current change (from a quick look).However, both this experiment and the current change had the same results on Frama-C once combined with #48. The experiment was still slower but way less significantly (~2%).